<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/
Route::group(array('before' => 'auth|force.ssl'), function() {
	Route::get ( '/', array ('as' => 'home','uses' => 'HomeController@showWelcome'));
	Route::get('/call-detail', array ('as' => 'call-detail', 'uses' => 'CallController@callDetail'));
	Route::post('/call/load-result', array ('as' => 'loadresult','uses' => 'CallController@loadResult'));
	Route::get('/pricing-detail', array ('as' => 'pricing-detail','uses' => 'PricingController@pricingDetail'));

	Route::get('/call-input/{call_id?}', array ('as' => 'call-input','uses' => 'CallController@callInput'))->where('call_id', '[0-9]+');
	Route::get('/call-input-detail/{call_id}/{cnt?}', array ('as' => 'call-input-detail','uses' => 'CallController@callInputDetail'))->where('call_id', '[0-9]+')->where('cnt', '[0-9]+');
	Route::get('/call-staff', array ('as' => 'call-staff','uses' => 'HomeController@callStaff'));

	Route::get('/pricing-input/{call_id?}/{call_cnt?}', array ('as' => 'pricing-input','uses' => 'PricingController@pricingInput'))->where('call_id', '[0-9]+')->where('call_cnt', '[0-9]+');
	Route::get('/stock-list', array ('as' => 'stock-list','uses' => 'HomeController@stockList'));

	Route::get('/calendar', array ('as' => 'calendar','uses' => 'CalendarController@login'));
	Route::get('/calendar-modal', array ('as' => 'calendar-modal','uses' => 'CalendarController@modal'));
	Route::get('/calendar-test', array ('as' => 'calendar-test','uses' => 'CalendarController@test'));

	Route::get('/kpi', array ('as' => 'kpi','uses' => 'KpiController@kpi'));
	Route::get('/kpi/call-catch', array ('as' => 'call-catch','uses' => 'KpiController@callCatch'));
	Route::get('/kpi/get-negotiation-kpi', array ('as' => 'kpi-negotiation','uses' => 'KpiController@ajaxGetNegotiationKpi'));
	Route::get('/kpi/get-appointment-kpi', array ('as' => 'kpi-appointment','uses' => 'KpiController@ajaxGetAppointmentKpi'));
	Route::get('/kpi/get-call-volume-kpi', array ('as' => 'call-volume-kpi','uses' => 'KpiController@callVolume'));
	Route::get('/kpi/get-success-kpi', array ('as' => 'success-kpi','uses' => 'KpiController@callSuccess'));

	Route::post('/call-input/districts', array('as' => 'districts', 'uses' => function() {
		if(Request::ajax()){
			return Response::json(Address::getListDistrict(Input::get('province')));
		}
	}));
	Route::post('/call-input/zipcode', array('as' => 'zipcode', 'uses' => function() {
		if (Request::ajax()) {
			return Response::json(Address::getListZipcode(Input::get('province'), Input::get('district')));
		}
	}));
	Route::post('/call-input/subdistrict', array('as' => 'subdistrict', 'uses' => function() {
		if (Request::ajax()) {
			return Response::json(Address::getListSubDistrict(Input::get('province'), Input::get('district'), Input::get('zip_code')));
		}
	}));	Route::post('/call-input/model', array('as' => 'model', 'uses' => function() {
		if (Request::ajax()) {
			return Response::json(DropdownList::getModelList(Input::get('brand')));
		}
	}));
	Route::post('/call-input/searchmodel', array('as' => 'searchmodel', 'uses' => function() {
		if (Request::ajax()) {
			return Response::json(DropdownList::getSearchModelList(Input::get('brand'), Input::get('model')));
		}
	}));
	Route::post('/call-input/submodel', array('as' => 'submodel', 'uses' => function() {
		if (Request::ajax()) {
			return Response::json(DropdownList::getSubModelList(Input::get('brand'), Input::get('model'), Input::get('searchmodel')));
		}
	}));

	Route::get('/call-input/check-call-access/{call_id}', array ('as' => 'check-call-access','uses' => 'CallController@checkCallAccess'))->where('call_id', '[0-9]+');
	Route::post('/call-input/update-call-access', array('as' => 'update-call-access', 'uses' => 'CallController@updateCallAccess'));

	//CSRF authentication
	Route::group(array('before' => 'csrf'), function(){
		Route::post('/call-input/post/{call_id?}', array('as' => 'call.input.post', 'uses' => 'CallController@postCallInput'))
		->where('call_id', '[0-9]+');
		Route::post('/call-input-detail/post/{call_id}', array('as' => 'call.input.detail.post', 'uses' => 'CallController@postCallInputDetail'))
		->where('call_id', '[0-9]+');

		// routed for save pricing
		Route::post('/pricing-input/{call_id?}/{call_cnt?}', array ('as' => 'pricing-input.post','uses' => 'PricingController@postPricingInput'))->where('call_id', '[0-9]+')->where('call_cnt', '[0-9]+');
	});
});

Route::group(array('before' => 'user|force.ssl'), function() {

	Route::get('user/profile/{id}', array('as' => 'user.profile', 'uses' => 'UserController@showProfile'));

	Route::get('/user/login',  array('as' => 'user.login',      'uses' => 'UserController@getLogin'));
	Route::get('/user/logout', array('as' => 'user.logout',     'uses' => 'UserController@getLogout'));

	Route::get('/user/register', array('as' => 'user.register',     'uses' => 'UserController@getRegister'));

	//CSRF authentication
	Route::group(array('before' => 'csrf'), function(){
		Route::post('/user/register', array('as' => 'user.register.post', 'uses' => 'UserController@postRegister'));
		Route::post('/user/login', array('as' => 'user.login.post', 'uses' => 'UserController@postLogin'));
	});

});

App::missing(function($exception){
	return Response::view('404', array (), 404);
});